package com.meituan.controller;

import com.meituan.model.EvaluateEntity;
import com.meituan.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class EvaluateController {
    @Autowired
    EvaluateService evaluateService;

    @PostMapping("publishEvaluation")
    public Map<String ,Integer> publishEvaluation(@RequestBody EvaluateEntity evaluate){
        Map<String ,Integer> map = new HashMap<>();
        if(evaluateService.add(evaluate)==1){
            map.put("err_code",0);
        }else{
            map.put("err_code",1);
        }
        return map;
    }

    @GetMapping("getEvaluate")
    public Map getEvaluate(String shopId){
        Map map = new HashMap();
        List<EvaluateEntity> list = evaluateService.findByShopId(shopId);
        if(list.size()!=0){
            map.put("err_code",0);
            map.put("result",list);
        }else{
            map.put("err_code",1);
        }
        return map;
    }

}
